/*
 * BalloontipButton.java - Copyright Mar 1, 2012 Z Networks Group, Inc. All rights reserved.
 * Z Networks Group PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.andromeda.skadi.view.swing;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import net.java.balloontip.BalloonTip;
import net.java.balloontip.positioners.CenteredPositioner;

/**
 *
 * @author Dickinson Roman Arismendy Torres
 */
public class BalloontipButton extends JButton {

    private BalloonTip balloonTip;
    private JComponent balloonContent;

    public BalloontipButton() {
        setBorder(null);
        addActionListener(new ActionHandler());
        setIcon(getMyIcon());
    }

    private Icon getMyIcon() {
        Image img = ((ImageIcon)UIManager.getIcon("OptionPane.informationIcon")).getImage();
        Image newimg = img.getScaledInstance(10, 10, java.awt.Image.SCALE_SMOOTH);
        ImageIcon newIcon = new ImageIcon(newimg);
        return newIcon;
    }

    private class ActionHandler implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            if (balloonTip != null && balloonTip.isVisible()) {
                balloonTip.closeBalloon();
            } else {
                balloonTip = new BalloonTip(BalloontipButton.this, "Hola mundo");
                balloonTip.setPositioner(new CenteredPositioner(5));
            }

        }
    }
}
